import { moduleTypeRule } from "../options/base";
import { mySchoolStore } from "../store";

const orderPay = uniCloud.importObject(`admin-wx-pay`, {customUI: true});

/**
 * 微信支付
 * @param orderId 
 * @param prompt 
 * @returns 
 */
export async function wxStartPay(
    orderId: string,
    moduleType:moduleTypeRule,
    prompt: boolean | undefined = false
) {
    const schoolStore = mySchoolStore();

    if (prompt) {
        uni.showLoading({ title: `正在拉起` ,mask:true})
    }

    try {
        const result = await orderPay.startWxPay(orderId, schoolStore.mySchool._id,moduleType);

        if(result.myErrCode!=null){
            result.errCode=result.myErrCode;
        }
    
        if (prompt) { uni.hideLoading(); }

        return result;
    } catch (error) {
        if (prompt) { uni.hideLoading(); }
        console.error(`xxxxxx=> 调用开始支付方式 startPay 异常，异常信息如下： <=xxxxxx`)
        console.log(error)
        throw new Error()
    }

}

